// 牛牛冲钻五
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int n, k;
        cin >> n >> k;
        int count = 0, ret = 0;
        string s;
        cin >> s;
        for(char ch : s)
        {
            if(ch == 'L')
            {
                --ret;
                count = 0;
            }
            else
            {
                ++count;
                if(count >= 3)
                    ret += k;
                else
                    ++ret;
            }
        }
        cout << ret << endl;
    }
    return 0;
}

// 最长无重复子数组
class Solution {
    public:
        int maxLength(vector<int>& arr) {
            int ret = 0, n = arr.size();
            int left = 0, right = 0;
            int hash[100010] = {0};
            while(right < n)
            {
                int in = arr[right];
                hash[in]++;
                while(hash[in] > 1)
                {
                    int out = arr[left++];
                    hash[out]--;
                }
                ret = max(ret, right - left + 1);
                ++right;
            }
            return ret;
        }
    };

// 重排字符串
#include <iostream>
using namespace std;

const int N = 100010;

int n = 0;
char s[N];
char ret[N];

int main()
{
    cin >> n >> s;
    int hash[26] = {0};
    int maxIndex, maxCount = 0;
    for(int i = 0; i < n; i++)
    {
        if(maxCount < ++hash[s[i] - 'a'])
        {
            maxCount = hash[s[i] - 'a'];
            maxIndex = s[i] - 'a';
        }
    }
    
    if(maxCount > (n + 1) / 2) cout << "no" << endl;
    else
    {
        cout << "yes" << endl;
        int index = 0;
        while(maxCount--)
        {
            ret[index] = maxIndex + 'a';
            index += 2;
        }
        
        for(int i = 0; i < 26; i++)
        {
            if(hash[i] == 0 || i == maxIndex)
                continue;
            while(hash[i]--)
            {
                if(index >= n) index = 1;
                ret[index] = i + 'a';
                index += 2;
            }
        }
        for(int i = 0; i < n; i++)
            cout << ret[i];
        cout << endl;
    }
        
    
    return 0;
}